home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / lang / sofa.lha / sofa / smalleiffel / lib_se / switch_collection.e < prev    next >
Text File  |  2000-03-25  |  7KB  |  211 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. expanded class SWITCH_COLLECTION
  17.    --
  18.    -- Unique Global Object in charge of the `switch_collection'.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.  
  25.    dictionary: DICTIONARY[DICTIONARY[RUN_FEATURE,STRING],STRING] is
  26.          -- First STRING key is the name of a run type corresponding
  27.          -- to a RUN_CLASS.
  28.          -- Embedded dictionary gives all switching points.
  29.       once
  30.          !!Result.with_capacity(1024);
  31.       end;
  32.  
  33. feature {CALL_PROC_CALL}
  34.  
  35.    update(target: EXPRESSION; run_feature: RUN_FEATURE) is
  36.       -- Update the switch_collection such that `run_feature' can be
  37.       -- applied with `target'.
  38.       require
  39.          target /= Void;
  40.          run_feature /= Void
  41.       local
  42.          current_type: TYPE;
  43.          running: ARRAY[RUN_CLASS];
  44.       do
  45.          if target.is_current then
  46.          elseif target.is_manifest_string then
  47.          else
  48.             current_type := run_feature.current_type;
  49.             if current_type.is_reference then
  50.                running := current_type.run_class.running;
  51.                if running /= Void and then running.count > 1 then
  52.                   update_with(run_feature);
  53.                end;
  54.             end;
  55.          end;
  56.       end;
  57.  
  58. feature {SMALL_EIFFEL}
  59.  
  60.    c_define is
  61.          -- Produce C code for switches.
  62.       local
  63.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  64.          count1, count2, total: INTEGER;
  65.          switch: SWITCH;
  66.       do
  67.          if not dictionary.is_empty then
  68.             cpp.swap_on_c;
  69.             from
  70.                count1 := 1;
  71.             until
  72.                count1 > dictionary.count
  73.             loop
  74.                dictionary2 := dictionary.item(count1);
  75.                from
  76.                   count2 := 1;
  77.                until
  78.                   count2 > dictionary2.count
  79.                loop
  80.                   switch.c_define(dictionary2.item(count2));
  81.                   total := total + 1;
  82.                   count2 := count2 + 1;
  83.           if total \\ 18 = 0 then
  84.              cpp.padding_here;
  85.           end;
  86.                end;
  87.                count1 := count1 + 1;
  88.             end;
  89.          end;
  90.          echo.print_count("Defined Switche",total);
  91.       end;
  92.  
  93.    afd is
  94.       local
  95.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  96.          count1, count2: INTEGER;
  97.          rf: RUN_FEATURE;
  98.          switch: SWITCH;
  99.       do
  100.          from
  101.             count1 := 1;
  102.          until
  103.             count1 > dictionary.count
  104.          loop
  105.             dictionary2 := dictionary.item(count1);
  106.             from
  107.                count2 := 1;
  108.             until
  109.                count2 > dictionary2.count
  110.             loop
  111.                rf := dictionary2.item(count2);
  112.                switch.afd(rf);
  113.                count2 := count2 + 1;
  114.             end;
  115.             count1 := count1 + 1;
  116.          end;
  117.       end;
  118.  
  119. feature {CECIL_POOL,ADDRESS_OF_POOL}
  120.  
  121.    update_with(run_feature: RUN_FEATURE) is
  122.       require
  123.          run_feature /= Void
  124.       local
  125.          current_type: TYPE;
  126.          key1, key2: STRING;
  127.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  128.          running: ARRAY[RUN_CLASS];
  129.       do
  130.          current_type := run_feature.current_type;
  131.          running := current_type.run_class.running;
  132.          if running /= Void and then running.count > 1 then
  133.             key1 := current_type.run_time_mark;
  134.             key2 := run_feature.name.to_key;
  135.             if dictionary.has(key1) then
  136.                dictionary2 := dictionary.at(key1);
  137.                if not dictionary2.has(key2) then
  138.                   dictionary2.put(run_feature,key2);
  139.                   small_eiffel.incr_magic_count;     
  140.                end;
  141.             else
  142.                !!dictionary2.make;
  143.                dictionary2.put(run_feature,key2);
  144.                dictionary.put(dictionary2,key1);
  145.                small_eiffel.incr_magic_count;     
  146.             end;
  147.             check
  148.                dictionary.at(key1).at(key2) = run_feature
  149.             end;
  150.          end;
  151.       end;
  152.  
  153. feature {C_PRETTY_PRINTER}
  154.  
  155.    remove(run_feature: RUN_FEATURE) is
  156.       require
  157.          run_feature /= Void
  158.       local
  159.          current_type: TYPE;
  160.          key1, key2: STRING;
  161.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  162.       do
  163.          current_type := run_feature.current_type;
  164.          key1 := current_type.run_time_mark;
  165.          if dictionary.has(key1) then
  166.             dictionary2 := dictionary.at(key1);
  167.             key2 := run_feature.name.to_key;
  168.             dictionary2.remove(key2);
  169.             check
  170.                not dictionary.at(key1).has(key2)
  171.             end;
  172.          end;
  173.       end;
  174.  
  175. feature {JVM}
  176.  
  177.    jvm_define is
  178.          -- Produce Java byte code for switches.
  179.       local
  180.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  181.          count1, count2, total: INTEGER;
  182.          switch: SWITCH;
  183.          up_rf: RUN_FEATURE;
  184.       do
  185.          if not dictionary.is_empty then
  186.             from
  187.                count1 := 1;
  188.             until
  189.                count1 > dictionary.count
  190.             loop
  191.                dictionary2 := dictionary.item(count1);
  192.                from
  193.                   count2 := 1;
  194.                until
  195.                   count2 > dictionary2.count
  196.                loop
  197.                   up_rf := dictionary2.item(count2);
  198.                   jvm.set_current_frame(up_rf);
  199.                   switch.jvm_define(up_rf);
  200.                   total := total + 1;
  201.                   count2 := count2 + 1;
  202.                end;
  203.                count1 := count1 + 1;
  204.             end;
  205.          end;
  206.          echo.print_count("Defined Switche",total);
  207.       end;
  208.  
  209. end -- SWITCH_COLLECTION
  210.  
  211.